// 供应商评分
import { defHttp } from '/@/utils/http/axios';
import { ErrorMessageMode } from '/#/axios';
enum Api {
  GetModelList = '/rating/model', // 查询模型列表
  AddModel = '/rating/model', // 添加模型
  DelModel = '/rating/model/batch', // 批量删除模型
  GetModelSelectList = '/rating/selects', // 模型下拉
  GetScoreList = '/rating/record', // 评分列表
  ExportRecord = '/rating/record/export', // 下载供应商明细
  SubmitRating = '/rating/submit', // 确定评分
  ChangeStatus = '/rating/change/status', // 修改模型状态
}

import type {
  GetIndicatorDetailsResponseInter,
  IndicatorDetailsMinorOptionsResponseInter,
} from '/#/viewTypes/sourcingBigData';

// 查询评分模型列表
export function getModelList(params: any, mode: ErrorMessageMode = 'message') {
  return defHttp.get(
    { url: Api.GetModelList, params },
    {
      errorMessageMode: mode,
    },
  );
}

// 查询评分模型下拉
export function getModelSelectList(mode: ErrorMessageMode = 'message') {
  return defHttp.get(
    { url: Api.GetModelSelectList },
    {
      errorMessageMode: mode,
    },
  );
}

// 添加模型
export function addModel(params: any, mode: ErrorMessageMode = 'message') {
  return defHttp.post(
    { url: Api.AddModel, params },
    {
      errorMessageMode: mode,
    },
  );
}

// 删除供应商名单 逗号分隔
export async function deleteModel(ids: string, mode: ErrorMessageMode = 'message') {
  return defHttp.delete<number>(
    {
      url: Api.DelModel + `?ids=${ids}`,
    },
    {
      errorMessageMode: mode,
    },
  );
}

// 查询评分列表
export function getScoreList(params: any, mode: ErrorMessageMode = 'message') {
  return defHttp.get(
    { url: Api.GetScoreList, params },
    {
      errorMessageMode: mode,
    },
  );
}

// 下载供应商明细
export function exportRecord(params: any, mode: ErrorMessageMode = 'message') {
  return defHttp.download(
    {
      url: Api.ExportRecord,
      method: 'GET',
      params,
      responseType: 'blob',
    },
    {
      errorMessageMode: mode,
    },
  );
}

// 提交评分
export function submitRating(params: any, mode: ErrorMessageMode = 'message') {
  return defHttp.post(
    { url: Api.SubmitRating, params },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 根据模型id 获取指标详情列表
 * @param id
 * @returns
 */
export const getIndicatorDetailsListApi = (id: string) =>
  defHttp.request<GetIndicatorDetailsResponseInter>({
    method: 'get',
    url: `/rating/model/${id}`,
    params: {},
  });

/**
 * 获取模型下 指标细项 条件配置
 * @returns
 */
export const getIndicatorDetailsMinorOptionsApi = () =>
  defHttp.request<IndicatorDetailsMinorOptionsResponseInter>({
    method: 'get',
    url: '/rating/model/metric/select',
    params: {},
  });

/**
 * 保存模型配置
 * @param data
 * @returns
 */
export const saveIndicatorDetailsModelApi = (data) =>
  defHttp.request({
    method: 'post',
    url: '/rating/model/save',
    data,
  });

/**
 * 下载评分结果报告
 * @param recordId
 * @returns
 */
export const downloadRecordPdfApi = (recordId: string | number) =>
  defHttp.download({
    method: 'get',
    url: `/rating/record/report/download/${recordId}`,
    responseType: 'blob',
    params: {},
  });

// 修改状态
export async function changeStatus(params: any, mode: ErrorMessageMode = 'message') {
  return defHttp.put(
    {
      url: Api.ChangeStatus,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
